package com.powerunion.datacollection.workflow.service.impl;

import org.apache.log4j.Logger;

import com.powerunion.datacollection.common.SystemException;
import com.powerunion.datacollection.dao.CollectionTaskInstanceDao;
import com.powerunion.datacollection.dao.DaoException;
import com.powerunion.datacollection.dao.DaoFactory;
import com.powerunion.datacollection.workflow.domain.TaskInstance;
import com.powerunion.datacollection.workflow.service.ITaskService;
import com.powerunion.datacollection.workflow.service.WFServiceException;
import com.powerunion.util.log.LogHelper;

public class TaskServiceImpl implements ITaskService {
	private static Logger logger = LogHelper.getInstance().getLogger(
			TaskServiceImpl.class);
	private CollectionTaskInstanceDao dao = null;
	
	public TaskServiceImpl(){
		super();
		this.dao = (CollectionTaskInstanceDao) DaoFactory.getInstance().getDao(
				CollectionTaskInstanceDao.class);
	}
	 
	public TaskInstance save(TaskInstance taskInstance) throws WFServiceException,DaoException {
		// 参数为空
		if (taskInstance == null) {
			String[] args = { "taskInstance" };
			// 打印错误日志
			StringBuffer msglog = new StringBuffer(
					"empty invoke parameter taskInstance NULL ");
			logger.error(msglog.toString());
			throw new SystemException("error.common.parameter.empty", args);
		}

		String[] codes = new String[1];
		codes[0] = taskInstance.getId();
		this.dao.delete(codes);
		
		taskInstance = this.dao.save(taskInstance);
		
		return taskInstance;
	}

}
